package com.example.train.app.service.impl;

import com.example.train.api.dto.DepartmentDTO;
import com.example.train.app.service.DepartmentService;
import com.example.train.app.service.assembler.DepartmentAssembler;
import com.example.train.domain.entity.Department;
import com.example.train.domain.repository.DepartmentRepository;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: ActingK20 42643
 * @Date: 2023/3/25 13:54
 */
@Service
public class DepartmentServiceImpl implements DepartmentService{
    private final DepartmentRepository repository;

    public DepartmentServiceImpl(DepartmentRepository repository) {
        this.repository = repository;
    }

    @Override
    public List<Department> ListDepartments(Long id) {
        return repository.findDepartmentByCondition(id);
    }

    @Override
    public Integer IntDepartments(DepartmentDTO departmentDTO) {
        return repository.insertDepartmentByCondition(DepartmentAssembler.toDepartment(departmentDTO));
    }

    @Override
    public Integer delDepartment(Long id) {
        return repository.delDepartmentByCondition(id);
    }

    @Override
    public Integer updateDepartments(DepartmentDTO departmentDTO) {
        return repository.updateDepartmentByCondition(DepartmentAssembler.toDepartment(departmentDTO));
    }
}
